package core

class SimpleTagLib {
	static namespace = "my "


	def myFlash = {
		flash.keySet().each {
			if (flash[it])
				out << "<div class=\"flash ${it}\">${flash[it]}</div>"
		}
	}

	def emoticon = { attrs, body ->
		out << body() << (attrs.happy == 'true' ? " :-)" : " :-(")
	}

	def countryDiv = { attrs, body ->
		def country = attrs.country
		out << "<div id=\"${country.id}\">"
		out << "${country.name} (${country.code})"
		out << "</div>"
	}
	def countryTemp = { attrs, body ->
		out << render(template: "country", model: [country: attrs.country])
	}
	def countriesDiv = { attrs, body ->
		def countries = attrs.countries
		countries.each {
			out << my.countryDiv (country:it)
		}
	}
	def repeat = { attrs, body ->
		attrs.times?.toInteger()?.times { num ->
			out << body(num)
		}
	}
}
